package models;

import models.constants.DeletedStatus;
import product.ProductSpec;
import util.common.UStringUtil;

import javax.persistence.*;
import java.util.List;

/**
 * Created by liming on 16/7/16.
 * 采购入库明细
 */
@Entity
@Table(name = "admin_stock_in_item")
public class AdminStockInItem extends BaseModel {

    /**
     * 采购入库单
     */
    @ManyToOne
    @JoinColumn(name = "admin_stock_in_id")
    public AdminStockIn adminStockIn;

    /**
     * 相应规格产品
     */
    @ManyToOne
    @JoinColumn(name = "product_spec_id")
    public ProductSpec productSpec;

    /**
     * 实际单价
     */
    @Column(name = "price")
    public Double price;

    /**
     * 采购单价
     */
    @Column(name = "purchase_price")
    public Double purchasePrice;

    /**
     * 提交数量
     */
    @Column(name = "submit_num")
    public Double submitNum;

    /**
     * 库管确认数量
     */
    @Column(name = "confirm_num")
    public Double confirmNum;

    /**
     * 入库金额
     */
    @Column(name = "amount")
    public Double amount;

    /**
     * 备注
     */
    @Column(name = "remark")
    public String remark;

    /**
     * 获取采购单清单
     */
    public static List<AdminStockInItem>  loadStockInItem(long id){
        return  AdminStockInItem.find("adminStockIn.id=? and adminStockIn.deletedStatus=?",id, DeletedStatus.UN_DELETED).fetch();
    }

    /**
     * 删除采购明细
     */
    public static void deleteItem(Integer[] delItemIdArray){

        String delIdStr = UStringUtil.concatStr(",", delItemIdArray);
        AdminStockInItem.delete("id in (" + delIdStr + ")");
    }


}
